<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.min.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.easyui.min.js"></script>
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/icon.css" />
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/black/easyui.css" />
<script type="text/javascript" src="js/common.js"></script>
<title>回款计划</title>
</head>
<body>
	<style type="text/css">
.step {
	margin-top: 20px;
}
</style>
	<script type="text/javascript">
		$(function() {
			$("#zj-back-plan-dg")
					.datagrid(
							{
								fit : true,
								border : false,
								toolbar : '#zj-back-plan-tb',
								pageSize : 9,
								pageList : '[5,8,9,10,15,20]',
								fitColumns : true,
								url : 'getAllBackPlan',
								method : 'get',
								singleSelect : false,
								pagination : true,
								columns : [ [
										{
											field : 'backPlan',
											width : 1,
											checkbox : true
										},
										{
											field : 'bpId',
											title : 'ID',
											width : 1
										},
										{
											field : 'bpCusName',
											title : '客户',
											width : 1
										},
										{
											field : 'bpCoName',
											title : '合同/订单',
											width : 2
										},
										{
											field : 'bpMoney',
											title : '金额',
											width : 1
										},
										{
											field : 'bpTime',
											title : '计划回款日期',
											width : 1,
											formatter : function(value, row,
													index) {
												if (value) {
													var date = new Date(value);
													var y = date.getFullYear();
													var m = date.getMonth() + 1;
													var d = date.getDate();
													return y + '-' + m + '-'
															+ d;
												}
											}
										},
										{
											field : 'bpPeriod',
											title : '期次',
											width : 1
										},
										{
											field : 'bpIfBack',
											title : '是否回款',
											width : 1
										},
										{
											field : 'bpOwner',
											title : '所有者',
											width : 1,
										},
										{
											field : 'backcaozuo',
											title : '操作',
											width : 2,
											formatter : function(value, row,
													index) {
												var editBackPlan = '<a class="zj-back-plan-edit" onclick="editBackPlan('
														+ row.bpId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												var deleteBackPlan = '<a class="zj-back-plan-delete" onclick="deleteBackPlan('
														+ row.bpId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												return editBackPlan
														+ deleteBackPlan;
											}
										} ] ],
								onLoadSuccess : function(data) {
									$('.zj-back-plan-edit').linkbutton({
										text : '编辑',
										plain : true,
										iconCls : 'icon-edit'
									});
									$('.zj-back-plan-delete').linkbutton({
										text : '删除',
										plain : true,
										iconCls : 'icon-cancel'
									});
								},
								rowStyler : function(index, row) {
									return 'height:30px';
								}
							});

			$("#zj_backplan_list_all").linkbutton({
				onClick : function() {
					$("#zj-back-plan-dg").datagrid({
						pageNumber : 1,
						url : 'getAllBackPlan'
					});
					$("#zj-back-plan-dg").datagrid("reload");
				}
			});

			$("#zj_btn_backplan_add").linkbutton({
				onClick : function() {
					$("#zj-back-plan-add-dialog").dialog({
						title : '新建回款计划',
						href2:'addNewBackPlan'
					});
					$("#zj-back-plan-form").form("clear");
					$("#zj-sgf-form-cus").textbox({
						readonly : false
					});
					$("#zj-back-plan-add-dialog").dialog("open");
				}
			});

			$("#zj-cusid-hidden").textbox({
				onChange : function() {
					var coId = $('#zj-cusid-hidden').textbox('getValue');
					$('#zj-sgf-input-order').combobox({
						url : 'getOrdersById?coId=' + coId,
						valueField : 'coId',
						textField : 'coTheme'
					});
				}
			});

			$("#zj-sgf-input-order").combobox({
				onSelect : function(oid) {
					$("#zj-sgf-input-ordercoid").textbox("setValue", oid.coId);
				}
			});
		});

		function editBackPlan(bpId) {
			$("#zj-back-plan-add-dialog").dialog({
				title : '编辑回款计划',
				href2:'editNewBackPlan'
			});
			$("#zj-back-plan-form")
					.form("load", 'getBackPlanById?bpId=' + bpId);
			$("#zj-sgf-form-cus").textbox({
				readonly : true
			});
			$("#zj-back-plan-add-dialog").dialog("open");
		}
		
		function deleteBackPlan(bpId){
			$.messager.confirm('提示', '确定要删除吗？', function(v) {
				if (v) {
					$.getJSON('deleteBackPlan', {
						bpId : bpId
					}, function(obj) {
						if (obj.success) {
							$('#zj-back-plan-dg').datagrid('reload');
						} else {
							$.messager.alert('提示', '操作失败, 原因：' + obj.message);
						}
					});
				}
			});
		}
	</script>
	<div id="zj-back-plan-tb">
		<a id="zj_btn_backplan_add" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">添加</a><a
			id="zj_backplan_list_all" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a>
	</div>
	<table id="zj-back-plan-dg"></table>
	<div id="zj-back-plan-add-dialog" class="easyui-dialog"
		style="width: 460px; height: 480px; padding: 10px;"
		data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true,buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
				var row = $('#zj-back-plan-dg').datagrid('getSelected');
					$('#zj-back-plan-form').form({
						url:$('#zj-back-plan-add-dialog').dialog('options').href2,
						method:'post',
						onSubmit:function(params){
						if (row != null) {
						params.bpId = row.bpId;
						}
							return $(this).form('validate');
						},
						success:function(v){
							var obj = eval('('+v+')');
							if(obj.success){
								$('#zj-back-plan-dg').datagrid('reload');
							}else{
							$.messager.alert('提示', '操作失败, 原因：' + obj.message);
							}
							$('#zj-back-plan-add-dialog').dialog('close');
						}
					}).submit();
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
					$('#zj-back-plan-add-dialog').dialog('close');
				}
			}]">

		<form id="zj-back-plan-form" method="post">
			<!-- <input  name="bpId"> -->
			<div class="step">
				<input id="zj-cusid-hidden" type="hidden" class="easyui-textbox"
					name="bpCusId"> <input id="zj-sgf-form-cus"
					name="bpCusName" class="easyui-textbox"
					data-options="editable:false,buttonText:'选择客户',required:true,label:' ', labelWidth:'80', width: 300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-sgf-form-cus').textbox('setValue', row.custName);
							$('#zj-sgf-form-cus').textbox('setText', row.custName);
							$('#zj-cusid-hidden').textbox('setValue', row.custId);
						});		
					}">
			</div>
			<div class="step">
				<input id="zj-sgf-input-ordercoid" name="bpCoId" type="hidden"
					class="easyui-textbox"> <input id="zj-sgf-input-order"
					class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',required:true,labelAlign:'right',label:'订单',
					width:250, labelWidth:90"
					name="bpOrderName">
			</div>

			<div class="step">
				<input class="easyui-datebox"
					data-options="required:true,labelAlign:'right',label:'计划回款日期',
					width:300, labelWidth:95"
					name="bpTime">
			</div>

			<div class="step">
				<select class="easyui-combobox"
					data-options="panelHeight:'auto',labelAlign:'right',required:true,label:'期次',
					width:280, labelWidth:90"
					name="bpPeriod">
					<option disabled selected value=''></option>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5">5</option>
					<option value="6">6</option>
					<option value="7">7</option>
					<option value="8">8</option>
					<option value="9">9</option>
					<option value="10">10</option>
					<option value="11">11</option>
					<option value="12">12</option>
				</select>
			</div>

			<div class="step">
				<input class="easyui-numberbox" name="bpMoney"
					data-options="min:0,precision:0,labelAlign:'right',required:true,label:'金额',
							width:200, labelWidth:90">
			</div>

			<div class="step" style="margin-left: 30px;">
				是否回款<input style="margin-left: 20px;" value="已回" name="bpIfBack"
					type="radio">已回<input value="未回" name="bpIfBack"
					type="radio">未回
			</div>

			<div class="step">
				<input id="zj-sgf-form-owner" name="bpOwner" class="easyui-textbox"
					data-options="editable:false,buttonText:'所有者',label:' ',labelWidth:'90', width: 300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-sgf-form-owner').textbox('setValue', row.custName);
							$('#zj-sgf-form-owner').textbox('setText', row.custName);
						});
					}">
			</div>
		</form>
	</div>

</body>
</html>